package com.yanqu.road.server.cmd.vehicle;

import com.yanqu.road.entity.config.vehicle.VehicleRecycleResult;
import com.yanqu.road.pb.vehicle.VehicleProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.vehicle.VehicleModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.server.command.Cmd;

import java.util.List;

@Cmd(code = Protocol.S_VEHICLE_RECYCLE, desc = "座骑回收")
public class VehicleRecycleCmd extends AbstractCommand {

	List<String> vehicleUidList;
	VehicleRecycleResult result;

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		VehicleProto.VehicleRecycleReqMsg reqMsg = VehicleProto.VehicleRecycleReqMsg.parseFrom(packet.getBytes());
		vehicleUidList = reqMsg.getVehicleUidList();
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		result = player.getModule(VehicleModule.class).vehicleRecycle(vehicleUidList, false);
	}

	@Override
	public void sendData(GamePlayer player) {
		if(null != result) {
			VehicleProto.VehicleRecycleRespMsg.Builder respMsg = VehicleProto.VehicleRecycleRespMsg.newBuilder();
			respMsg.setRet(result.getRet());
			if(0 == result.getRet()){
				respMsg.addAllVehicleUid(result.getRecycleVehicleUidList());
				respMsg.setRewards(result.getRecycleReward());
			}
			player.sendPacket(Protocol.U_VEHICLE_RECYCLE , respMsg);
		}

	}

}
